package  
{
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.filters.BevelFilter;
	import flash.utils.Timer;
	/**
	 * Brique à détruire
	 * @author Jean-Marie PETIT@hsh
	 */
	public class Brique extends Shape
	{
		private var _mur:Mur
		private var _chrono:Timer = new Timer(3000);
		public function Brique(mur:Mur, px:int, py:int, couleur:int) 
		{
			_mur = mur;
			
			// Dessin
			graphics.lineStyle(0, 0, .5, true, "none", "round");
			new Degrade(graphics, 40, 18, 6, [0xFFFFFF, couleur, 0x333333],[1,1,1],[0,200,255]);
			
			// Affichage
			x = px;
			y = py;
			_mur.addChild(this);
			_mur.briques.push(this);
			
			// Déplacement
			_chrono.addEventListener(TimerEvent.TIMER, descendre);
			_chrono.start();
		}
		
		private function descendre(t:TimerEvent):void 
		{
			y = Math.min(180, y + Math.random()*8);
		}
		
		public function exploser():void
		{
			addEventListener(Event.ENTER_FRAME, _disparition);
			_mur.briques.splice(_mur.briques.indexOf(this), 1);
			_mur.afficher();
			_chrono.stop();
			_chrono.removeEventListener(TimerEvent.TIMER, descendre);
		}
		
		private function _disparition(e:Event):void 
		{
			alpha -= 0.1;
			width -= 2;
			height --;
			x ++;
			y += 0.5;
			if (alpha <= 0) 
			{
				removeEventListener(Event.ENTER_FRAME, _disparition);
				_mur.removeChild(this);
			}
		}
	}
}